local Mongo = require "core.Mongo"
local PlayerBanListMongo = Mongo.playerBanList
local IpBanListMongo = Mongo.ipBanList

local M = {}

function M.banPlayer(playerId, endTime, reason, desc)
    PlayerBanListMongo:upsertOne({
        playerId = playerId
    }, {
        playerId = playerId,
        endTime = endTime,
        reason = reason,
        des = desc
    })
end

function M.unbanPlayer(playerId)
    PlayerBanListMongo:deleteOne({
        playerId = playerId
    })
end

-- 获取玩家封禁列表
function M.getPlayerBanList()
    return PlayerBanListMongo:findMany()
end

function M.resetPlayerBanList(data)
    PlayerBanListMongo:deleteMany({})
    if table.empty(data) then
        return
    end

    PlayerBanListMongo:insertMany(data)
end

function M.banIP(ip, endTime, reason, desc)
    IpBanListMongo:upsertOne({
        ip = ip
    }, {
        ip = ip,
        endTime = endTime,
        reason = reason,
        des = desc
    })
end

function M.unbanIP(ip)
    IpBanListMongo:deleteOne({
        ip = ip
    })
end

function M.getIpBanList()
    return IpBanListMongo:findMany()
end

function M.resetIpBanList(data)
    IpBanListMongo:deleteMany({})
    if table.empty(data) then
        return
    end

    IpBanListMongo:insertMany(data)
end

return M
